﻿<?php

if (!defined('IN_MEDIA')) die("Hack");

function rating_img($rate,$rate_tt) {

   	global $r_s_img;

	if ($rate_tt =='0') $rating = 0;

	else $rating = $rate / $rate_tt;

	if ($rating <= 0  ){$star = "star00";}

	if ($rating >= 0.5){$star = "star05";}

	if ($rating >= 1  ){$star = "star10";}

	if ($rating >= 1.5){$star = "star15";}

	if ($rating >= 2  ){$star = "star20";}

	if ($rating >= 2.5){$star = "star25";}

	if ($rating >= 3  ){$star = "star30";;}

	if ($rating >= 3.5){$star = "star35";}

	if ($rating >= 4  ){$star = "star40";}

	if ($rating >= 4.5){$star = "star45";}

	if ($rating >= 5  ){$star = "star50";}		

	$r_s_img = 	"<p class=\"view_r $star\"></p>";

}



function m_setcookie($name, $value = '', $permanent = true) {

	global $web_link;

	$setCookieType=1;	

	$expire = ($permanent)?(time() + 60 * 60 * 24 * 365):0;

	

	if ($setCookieType == 1) {

		$url = $web_link;

		if ($url[strlen($url)-1] != '/') $url .= '/';

		$secure = (($_SERVER['HTTPS'] == 'on' OR $_SERVER['HTTPS'] == '1') ? true : false);

		$p = parse_url($url);

		$path = !empty($p['path']) ? $p['path'] : '/';

		$domain = $p['host'];

		if (substr_count($domain, '.') > 1) {

			while (substr_count($domain, '.') > 1)

			{

				$pos = strpos($domain, '.');

				$domain = substr($domain, $pos + 1);

			}

			

		}

		else $domain = '';

		@setcookie($name, $value, $expire, $path, $domain, $secure);

	}

	else @setcookie($name,$value,$expire);

}

function m_checkLogin(){

	global $mysql, $tb_prefix;

	

	if ($_COOKIE['USER']) {

		$identifier = $_COOKIE['USER'];

		$q = $mysql->query("SELECT user_identifier, user_id, user_name FROM ".$tb_prefix."user WHERE user_identifier = '".$identifier."'");

		if ($mysql->num_rows($q)) {

			$r = $mysql->fetch_array($q);

			$_SESSION['user_id'] = $r['user_id'];

			$_SESSION['user_name'] = $r['user_name'];

			$return = true;

		}

		else $return = false;

	}

	else $return = false;

	return $return;

}



function get_total($table,$f1,$f2 = '') {

	global $mysql, $tb_prefix;

	$q = "SELECT COUNT($f1) FROM ".$tb_prefix.$table;

	$q .= ($f2)?" ".$f2:'';

	$tt = $mysql->fetch_array($mysql->query($q));

	return $tt[0];

}

function m_check_random_str($str,$len = 5) {

	if (!ereg('^([A-Za-z0-9]){'.$len.'}$',$str)) return false;

	return true;

}

function replace($str) {

	$str = str_replace('%20', '-', $str);

	$str = str_replace(':', '-', $str);

	$str = str_replace('--', '', $str);

$str = str_replace('(', '', $str);

$str = str_replace(')', '', $str);

$str = str_replace('[', '', $str);

$str = str_replace(']', '', $str);

$str = str_replace('-', '', $str);

	$str = str_replace('-/', '/', $str);

	$str = str_replace(' ', '-', $str);

	return $str."";

}

function check_img($img) {

	if ($img == '') $img = $_SESSION['skin_folder']."/img/no_img.gif";

	return $img;

}



function check_data($name) {

	if ($name == '') $name = "Đang cập nhật";

	return $name;

}



function text_tidy($string) {

	$string = str_replace ( '&amp;', '&', $string );

	$string = str_replace ( "'", "'", $string );

	$string = str_replace ( '&quot;', '"', $string );

	$string = str_replace ( '&lt;', '<', $string );

	$string = str_replace ( '&gt;', '>', $string );

	return $string;

}



function cut_string($str,$len) {

	if ($str=='' || $str==NULL) return $str;

	if (is_array($str)) return $str;

	$str = trim($str);

	if (strlen($str) <= $len) return $str;

	$str = substr($str,0,$len);

	$str = $str.' ...';

	return $str;

}



function get_words($str,$num)

{

	$limit = $num - 1 ;

    $str_tmp = '';

    $arrstr = explode(" ", $str);

    if ( count($arrstr) <= $num ) { return $str; }

    if (!empty($arrstr))

    {

        for ( $j=0; $j< count($arrstr) ; $j++)    

        {

            $str_tmp .= " " . $arrstr[$j];

            if ($j == $limit) 

            {

                break;

            }

        }

    }

    return $str_tmp.' ...';

}

function check_str_old($a){

$n=intval(strlen($a)/21);

if($n>0)

{

for($i=1;$i<=$n;$i++)

{

$b=$b.substr($a,0,21)." ";

$a=substr($a,21,strlen($a));

}

}

else

{

$b=$a;

}

return $b;

}

function check_str($str) {$str2 = explode(' ',$str);$count = count($str2);for ($i= 0; $i < $count ; $i++){if(strlen($str2[$i]) < 10){$result .= $str2[$i].' ';continue;}$str3 = substr($str2[$i],0,10);$result .= $str3.' ';}return $result;}

function bad_words($str) {

	$chars = array('địt','Địt','ĐỊT','đéo','Đéo','ĐÉO','lồn','Lồn','LỒN','cặc','Cặc','CẶC','dái','Dái','DÁI','chó','Chó','CHÓ','Cứt','cứt','CỨT','ỉa','Ỉa','đái','Đái','ỈA');

	foreach ($chars as $key => $arr)

		$str = preg_replace( "/(^|\b)".$arr."(\b|!|\?|\.|,|$)/i", "***", $str ); 

		$str = wordwrap($str, 23, " ", true);

		$str = str_replace('<','&lt;',$str);

		$str = check_str($str);

	return $str;

}



function un_htmlchars($str) {

	return str_replace(array('&lt;', '&gt;', '&quot;', '&amp;', '&#92;', '&#39'), array('<', '>', '"', '&', chr(92), chr(39)), $str );

}



function htmlchars($str) {

	return str_replace(

		array('&', '<', '>', '"', chr(92), chr(39)),

		array('&amp;', '&lt;', '&gt;', '&quot;', '&#92;', '&#39'),

		$str

	);

}



function get_ascii($str) {

	$chars = array(

		'a'	=>	array('ấ','ầ','ẩ','ẫ','ậ','Ấ','Ầ','Ẩ','Ẫ','Ậ','ắ','ằ','ẳ','ẵ','ặ','Ắ','Ằ','Ẳ','Ẵ','Ặ','á','à','ả','ã','ạ','â','ă','Á','À','Ả','Ã','Ạ','Â','Ă'),

		'e' 	=>	array('ế','ề','ể','ễ','ệ','Ế','Ề','Ể','Ễ','Ệ','é','è','ẻ','ẽ','ẹ','ê','É','È','Ẻ','Ẽ','Ẹ','Ê'),

		'i'	=>	array('í','ì','ỉ','ĩ','ị','Í','Ì','Ỉ','Ĩ','Ị'),

		'o'	=>	array('ố','ồ','ổ','ỗ','ộ','Ố','Ồ','Ổ','Ô','Ộ','ớ','ờ','ở','ỡ','ợ','Ớ','Ờ','Ở','Ỡ','Ợ','ó','ò','ỏ','õ','ọ','ô','ơ','Ó','Ò','Ỏ','Õ','Ọ','Ô','Ơ'),

		'u'	=>	array('ứ','ừ','ử','ữ','ự','Ứ','Ừ','Ử','Ữ','Ự','ú','ù','ủ','ũ','ụ','ư','Ú','Ù','Ủ','Ũ','Ụ','Ư'),

		'y'	=>	array('ý','ỳ','ỷ','ỹ','ỵ','Ý','Ỳ','Ỷ','Ỹ','Ỵ'),

		'd'	=>	array('đ','Đ'),

	);

	foreach ($chars as $key => $arr) 

		foreach ($arr as $val)

			$str = str_replace($val,$key,$str);

	return $str;

}



function emotions_array() {

	return array(

		6 => '>:D<',		18 => '#:-S',				36 => '<:-P',		42 => ':-SS',

		48 => '<):)',		50 => '3:-O',				51 => ':(|)',		53 => '@};-',

		55 => '**==',		56 => '(~~)',				58 => '*-:)',		63 => '[-O<',

		67 => ':)>-',		77 => '^:)^',				106 => ':-??',		25 => 'O:)',

		26 => ':-B',		28 => 'I-)',				29 => '8-|',		30 => 'L-)',

		31 => ':-&',		32 => ':-$',				33 => '[-(',		34 => ':O)',

		35 => '8-}',		7 => ':-/',					37 => '(:|',		38 => '=P~',

		39 => ':-?',		40 => '#-O',				41 => '=D>',		9 => ':">',

		43 => '@-)',		44 => ':^O',				45 => ':-W',		46 => ':-<',

		47 => '>:P',		11 => array(':*',':-*'),	49 => ':@)',		12 => '=((',

		13 => ':-O',		52 => '~:>',				16 => 'B-)',		54 => '%%-',

		17 => ':-S',		5 => ';;)',					57 => '~O)',		19 => '>:)',

		59 => '8-X',		60 => '=:)',				61 => '>-)',		62 => ':-L',

		20 => ':((',		64 => '$-)',				65 => ':-"',		66 => 'B-(',

		21 => ':))',		68 => '[-X',				69 => '\:D/',		70 => '>:/',

		71 => ';))',		72 => 'O->',				73 => 'O=>',		74 => 'O-+',

		75 => '(%)',		76 => ':-@',				23 => '/:)',		78 => ':-J',

		79 => '(*)',		100 => ':)]',				101 => ':-C',		102 => '~X(',

		103 => ':-H',		104 => ':-T',				105 => '8->',		24 => '=))',

		107 => '%-(',		108 => ':O3',				1 => array(':)',':-)'),		2 => array(':(',':-('),

		3 => array(';)',';-)'),		22 => array(':|',':-|'),		14 => array('X(','X-('),		15 => array(':>',':->'),

		8 => array(':X',':-X'),		4 => array(':D',':-D'),		27 => '=;',		10 => array(':P',':-P'),

	);

}



function emotions_replace($s) {

	$emotions = emotions_array();

	foreach ($emotions as $a => $b) {

		$x = array();

		if (is_array($b)) {

			for ($i=0;$i<count($b);$i++) {

				$b[$i] = htmlchars($b[$i]);

				$x[] = $b[$i];

				$v = strtolower($b[$i]);

				if ($v != $b[$i]) $x[] = $v;

				}

		}

		else {

			$b = htmlchars($b);

			$x[] = $b;

			$v = strtolower($b);

			if ($v != $b) $x[] = $v;

		}

		$p = '';

		for ($u=0;$u<strlen($x[0]);$u++) {

			$ord = ord($x[0][$u]);

			if ($ord < 65 && $ord > 90) $p .= '&#'.$ord.';';

			else $p .= $x[0][$u];

		}

		$s = str_replace($x,'<img src="images/emoticons/'.$a.'.gif" />',$s); 

			

	}

	return $s;

}



function isFloodPost(){

	$_SESSION['current_message_post'] = time();

	global $wait_post;

	$timeDiff_post = $_SESSION['current_message_post'] - $_SESSION['prev_message_post'];

	$floodInterval_post	= 45;

	$wait_post = $floodInterval_post - $timeDiff_post ;	

	if($timeDiff_post <= $floodInterval_post)

	return true;

	else 

	return false;

}
#######################################
# FUNCTIONS RELATE EPISODE
#######################################
function episode_show($total_episode,$film_id,$episode_id,$episode_name){
	global $mysql,$tb_prefix,$link_href;
	$q = $mysql->query("SELECT episode_id, episode_name, episode_type FROM ".$tb_prefix."episode WHERE episode_film = ".$film_id." ORDER BY episode_id ASC");
	$film = $mysql->fetch_array($mysql->query("SELECT film_name, film_name_ascii, film_name_real FROM ".$tb_prefix."film WHERE film_id = '".$film_id."'"));
	     while ($r = $mysql->fetch_array($q)){
			$episode_type = $r['episode_type'];
		    $sv[$episode_type] .= "<a href=\"xem-phim-".replace($film['film_name_ascii'].'/m'.$r['episode_id']).'.html'."\"><b>".$r['episode_name']."</b></a>&nbsp; ";
		}
$total_server .= "<table>";
if($sv[2]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Unknow Server:</font></b> &nbsp;".$sv[2]."</td></tr>";
if($sv[1]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Phimanhdao:</font></b> &nbsp;".$sv[1]."</td></tr>";
if($sv[3]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Phimanhdao2:</font></b> &nbsp;".$sv[3]."</td></tr>";
if($sv[5]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server youtube:</font></b> &nbsp;".$sv[5]."</td></tr>";
if($sv[9]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Phimanhdao4:</font></b> &nbsp;".$sv[9]."</td></tr>";
if($sv[8]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Mega:</font></b> &nbsp;".$sv[8]."</td></tr>";
if($sv[32]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server MegaF:</font></b> &nbsp;".$sv[32]."</td></tr>";
if($sv[34]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Gdata:</font></b> &nbsp;".$sv[34]."</td></tr>";
if($sv[33]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server VideoBB:</font></b> &nbsp;".$sv[33]."</td></tr>";
if($sv[12]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server VideoZer:</font></b> &nbsp;".$sv[12]."</td></tr>";
if($sv[18]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server M Share:</font></b> &nbsp;".$sv[18]."</td></tr>";
if($sv[37]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Twitvid:</font></b> &nbsp;".$sv[37]."</td></tr>";
if($sv[41]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server PiCas:</font></b> &nbsp;".$sv[41]."</td></tr>";
if($sv[4]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Youtube:</font></b> &nbsp;".$sv[4]."</td></tr>";
if($sv[6]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Megavid:</font></b> &nbsp;".$sv[6]."</td></tr>";
if($sv[30]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server CyWorld:</font></b> &nbsp;".$sv[30]."</td></tr>";
if($sv[31]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server ShareVnn:</font></b> &nbsp;".$sv[31]."</td></tr>";
if($sv[35]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Speedy:</font></b> &nbsp;".$sv[35]."</td></tr>";
if($sv[36]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server RuTube:</font></b> &nbsp;".$sv[36]."</td></tr>";
if($sv[39]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Rolo:</font></b> &nbsp;".$sv[39]."</td></tr>";
if($sv[40]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Weed:</font></b> &nbsp;".$sv[40]."</td></tr>";
if($sv[29]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Nova:</font></b> &nbsp;".$sv[29]."</td></tr>";
if($sv[24]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Vidx:</font></b> &nbsp;".$sv[24]."</td></tr>";
if($sv[26]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Vidb:</font></b> &nbsp;".$sv[26]."</td></tr>";
if($sv[25]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Ovfs:</font></b> &nbsp;".$sv[25]."</td></tr>";
if($sv[42]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Hulk:</font></b> &nbsp;".$sv[42]."</td></tr>";
if($sv[43]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server picas:</font></b> &nbsp;".$sv[43]."</td></tr>";
if($sv[44]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Divx:</font></b> &nbsp;".$sv[44]."</td></tr>";
if($sv[45]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Ooya:</font></b> &nbsp;".$sv[45]."</td></tr>";
if($sv[46]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Banb:</font></b> &nbsp;".$sv[46]."</td></tr>";
if($sv[47]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Glum:</font></b> &nbsp;".$sv[47]."</td></tr>";
if($sv[48]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server SF4U:</font></b> &nbsp;".$sv[48]."</td></tr>";
if($sv[49]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Govn:</font></b> &nbsp;".$sv[49]."</td></tr>";
if($sv[50]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server SeverHD:</font></b> &nbsp;".$sv[50]."</td></tr>";
if($sv[51]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Modo:</font></b> &nbsp;".$sv[51]."</td></tr>";
if($sv[52]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Zala:</font></b> &nbsp;".$sv[52]."</td></tr>";
if($sv[53]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Open:</font></b> &nbsp;".$sv[53]."</td></tr>";
if($sv[57]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server zingtv:</font></b> &nbsp;".$sv[57]."</td></tr>";
if($sv[55]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server vivo:</font></b> &nbsp;".$sv[55]."</td></tr>";
if($sv[7]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Tầm Tay:</font></b> &nbsp;".$sv[7]."</td></tr>";
if($sv[10]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Zing:</font></b> &nbsp;".$sv[10]."</td></tr>";
if($sv[11]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Clipvn:</font></b> &nbsp;".$sv[11]."</td></tr>";
if($sv[13]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Veoh:</font></b> &nbsp;".$sv[13]."</td></tr>";
if($sv[14]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Zing:</font></b> &nbsp;".$sv[14]."</td></tr>";
if($sv[15]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Seeon:</font></b> &nbsp;".$sv[15]."</td></tr>";
if($sv[16]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Dailymotion:</font></b> &nbsp;".$sv[16]."</td></tr>";
if($sv[17]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Vidd:</font></b> &nbsp;".$sv[17]."</td></tr>";
if($sv[19]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Badongo:</font></b> &nbsp;".$sv[19]."</td></tr>";
if($sv[20]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server N@T:</font></b> &nbsp;".$sv[20]."</td></tr>";
if($sv[23]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Sendspace:</font></b> &nbsp;".$sv[23]."</td></tr>";
if($sv[28]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server ZippyShare:</font></b> &nbsp;".$sv[28]."</td></tr>";
if($sv[21]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server 2shared:</font></b> &nbsp;".$sv[21]."</td></tr>";
if($sv[22]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server 4shared:</font></b> &nbsp;".$sv[22]."</td></tr>";
if($sv[27]) $total_server .= "<tr><td><b><img src=style/icon_server.png> <font color=#9966ff>Server Mediafire:</font></b> &nbsp;".$sv[27]."</td></tr>";
$total_server .= "</table>";
$total_server = str_replace('<a href="xem-phim-'.replace($film['film_name_ascii']).'/m'.$episode_id.'.html'.'"><b>'.$episode_name.'</b></a>','<a href="xem-phim-'.replace($film['film_name_ascii']).'/m'.$episode_id.'.html'.'"><font size="2" style="color:#CCCCCC;background-color: #006699;font-weight: bold">&nbsp;'.$episode_name.'&nbsp;</font></a> ',$total_server);
	return $total_server;
}
?>
